<div class="section">

	<div class="section-title">Danh sách kỳ báo</div>
    
    <div class="section-content">
    	
        <form action="" method="post" id="listitem" name="listitem">
        
        	<div class="button right">
            	<?php if($dialog != "true"){?>
                <?php if($list_button['insert']){ ?>	
                <a class="button add" href="<?php echo $insert?>">Thêm mới</a>
                <?php } ?>
                <?php if($list_button['delete']){ ?>
                <a class="button delete" onclick="deleteItem()">Xóa</a>
                <?php } ?>
                <?php } else { ?>
                <a class="button select" onclick="selectItem()">Chọn</a>
                <?php } ?>
                <a class="button exit" href="?route=deliman/home">Về trang chủ</a>
            </div>
            <div class="clearer">^&nbsp;</div>
            
           	<div id="ben-search">
				<script language="javascript">
                $(function() {
                    $("#tungay").datepicker({
                        changeMonth: true,
                        changeYear: true,
                        dateFormat: 'dd-mm-yy'
                    });
                    $("#denngay").datepicker({
                        changeMonth: true,
                        changeYear: true,
                        dateFormat: 'dd-mm-yy'
                    });
                    });
                </script>
                <div class="left" style="padding-bottom:10px; padding-left:20px">
                    <label>Loại báo:</label>&nbsp;&nbsp;&nbsp;&nbsp;
                    
                    <select id="loaibaoid" name="loaibaoid">
                        <option value="">----Chọn tất cả----</option>
                            <?php echo $loaibao ?>
                    </select>
                    
                    <label>Ngày phát hành: từ</label>
                    <input type="text" class="text" id="tungay" name="tungay" />&nbsp;&nbsp;&nbsp;&nbsp;
                    <label>đến:</label>
                    <input type="text" class="text" id="denngay" name="denngay" />&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
                <div class="left">
                	<a class="button-other search" id="searchForm">Tìm kiếm</a>
                </div>
                <div class="clearer">^&nbsp;</div>
            </div>
            
            <div class="sitemap treeindex">
                <table class="data-table" cellpadding="0" cellspacing="0">
                <tbody>
                    <tr class="tr-head">
                        <th width="1%"><input type="checkbox" onclick="$('input[name*=\'delete\']').attr('checked', this.checked);"></th>
                        
                        
                        <th>Tên kỳ báo</th>
                        <th>Tên loại báo</th>
                        <th>Ngày phát hành</th>
                        <th>Giá bán</th> 
                        
                        <?php if($dialog != "true"){?>
                        <th>Giá in</th>
                        <th>Chi phí khác</th>
                        <th>Tổng giá gốc</th>
                        <th>Số lượng in</th>
                        <th>Số trang</th>
                        <th>Ghi chú</th>
                        <th>Công cụ</th>   
                        <?php } ?>                               
                    </tr>
       	<?php
         if($thongbao==0)
            {
        ?>
        	<tr>
            	<td colspan="12">
                <div class="text-center">
            		<span class="thongbaokhongcodulieu">Không có dữ liệu trong hệ thống</span>
                </div>
                </td>
            </tr>
        
        <?php 
        }else{
        ?>

        <?php
        foreach($loaibaos as $loaibao)
        {
        	$tongcong = 0;
        ?>
            <tr>
                <th id="<?php echo 'loaibao'.$loaibao['loaibaoid']?>" colspan="12" class="other" >
                    <?php
                    if(trim($loaibao['tenloaibao'])!='')
                    	echo $loaibao['tenloaibao'];
                    ?>
                </th>
            </tr>
        <?php
            foreach($datas as $item)
            {
            	if($item['tenloaibao']==$loaibao['tenloaibao'])
                {
                	$tongcong++;
        ?>
                    <tr>
                        <td class="check-column"><input class="inputchk" type="checkbox" name="delete[<?php echo $item['kybaoid']?>]" value="<?php echo $item['kybaoid']?>" ></td>
                        
                        <td><?php echo $item['tenkybao']?></td>
                        <td><?php echo $item['tenloaibao']?></td>
                        <td><?php echo $this->date->formatMySQLDate($item['ngayphathanh'])?></td>
                        <td><?php echo $this->string->numberFormate($item['giaban'])?></td>
                  
                        
                        <?php if($dialog != "true"){?>
                              <td><?php echo $this->string->numberFormate($item['giain'])?></td>
                        <td><?php echo $this->string->numberFormate($item['chiphikhac'])?></td>
                        <td><?php echo $this->string->numberFormate($item['tonggiagoc'])?></td>
                        <td><?php echo $this->string->numberFormate($item['soluongin'])?></td>
                        <td><?php echo $this->string->numberFormate($item['sotrang'])?></td>
                        <td><?php echo $item['ghichu']?></td>
                        <td class="link-control">
                        	<?php if($list_button['update']){ ?>
                           	<a class="button edit" rel="<?php echo $item['kybaoid'] ?>" href="<?php echo $item['link_edit']?>">Sửa</a>
                            <?php } ?>
                        </td>
                        <?php } ?>
                    </tr>
        <?php
        		}
            }
            
            if($tongcong == 0)
            {
        ?>
        
        		<script language="javascript">
							$temp = "<?php echo 'loaibao'.$loaibao['loaibaoid']?>";
							$("#"+$temp).hide();
               </script>
        <?php
        	}
            }
        }
        
        
        ?>
                        
                                                    
                </tbody>
                </table>
            </div>
        	<?php echo $pager?>
        
        </form>
        
    </div>
    
</div>
<script language="javascript">
$(document).ready(function(){
		$('#loaibaoid').change(function(){
			$('#kybaoid').load('?route=deliman/kybao/getdkkybao&loaibaoid='+$('#loaibaoid').val(),function(){
				$("#kybaoid").val("<?php echo $_GET['kybaoid']?>");
		});
		$('#searchForm').click(function(){
			
			 searchForm();
		});
	});
	$('#loaibaoid').change();
});
$("#loaibaoid").val("<?php echo $_GET['loaibaoid']?>");

function deleteItem()
{
	var answer = confirm("Bạn có muốn xóa không?")
	if (answer)
	{
		$.post("?route=deliman/kybao/delete", 
				$("#listitem").serialize(), 
				function(data)
				{
					if(data=="true")
					{
						alert("Xóa thành công");
						window.location.reload();
					}
				}
		);
	}
}

function selectItem()
{
	var str =""
	
	$('.inputchk').each(function(){
		
		if(this.checked == true)
		{
			str += this.value + ",";
		}
	});
	
	opener.document.frm.selectkybao.value = str;
	window.close();
}

function searchForm()
{
	var url =  "?route=deliman/kybao";
	if($("#loaibaoid").val() != "")
		url += "&loaibaoid="+ $("#loaibaoid").val();
	if($("#tungay").val() != "")
		url += "&tungay="+ $("#tungay").val();
	if($("#denngay").val() != "")
		url += "&denngay="+ $("#denngay").val();
	
	if("<?php echo $_GET['dialog']?>" == "true")
		url += "&dialog=true";
	window.location = url;
}

$("#tungay").val("<?php echo $_GET['tungay']?>");
$("#denngay").val("<?php echo $_GET['denngay']?>");
</script>